package cn.example.vip.mall.canal.listener;

import cn.example.vip.mall.permission.entity.Permission;
import cn.example.vip.mall.permission.feign.PermissionFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@Component
@CanalTable("permission")
public class PermissionHandler implements EntryHandler<Permission> {
	@Autowired
	private PermissionFeign permissionFeign;
	
	@Override
	public void insert(Permission Permission) {
		permissionFeign.updateRole();
	}
	
	@Override
	public void update(Permission before, Permission after) {
		// 判断权限是否变更?
		if(!before.getUrl().equals(after.getUrl())
			|| !before.getMethod().equals(after.getMethod())
			|| !before.getServiceName().equals(after.getServiceName())
			|| !before.getUrlMatch().equals(after.getUrlMatch())
		){
			permissionFeign.updateRole();
		}
	}
	
	@Override
	public void delete(Permission Permission) {
		permissionFeign.updateRole();
	}
}
